<?php
define('DOMAIN_MYSQLDBTYPE','mysql');

abstract class BaseDomain {
	private $entityName; 
	private $primaryKey;
	private $dbType;
	private $data;
	
	public function __construct($data, $entityName, $primaryKey, $dbType) {
		$this->data = $data;
		$this->entityName = $entityName;
		$this->primaryKey = $primaryKey;
		$this->dbType = $dbType;
	}
		
	public function getField($fieldName){
		if(isset($this->data[$fieldName]))
	       return $this->data[$fieldName];
        else
            return null;
	}
	
	public function setField($fieldName, $value){
		$this->data[$fieldName] = $value;
	}
	
	public function getOid() {
		return $this->getField($this->primaryKey);
	}
	
	protected function initOid() {
		if($this->getField($this->primaryKey) == null)
		{
			$this->setField($this->primaryKey,$oid);
		}
	}
	
	protected function getData() {
		return $this->data;
	}
	
	public function toArray() {
		$c = array();
		$b=array();
		$b = unserialize(serialize($this->data));
		if($b == null)	
			return $b;
		else {		
			foreach ($b as $a=>$val)
			{
				 $c[$a]  = $val ;
			}
		}
		return $c;		
	}
	
	public function getEntityName() {
		return $this->entityName;
	}
	
	public function getPrimaryKey() {
		return $this->primaryKey;
	}
	
	public function getDbType() {
		return $this->dbType;
	}
	
	public function __toString() {
		$stringValue = "";	
		try{
			$classname = get_class($this);
			$methodnames = get_class_methods($classname);
			foreach ($methodnames as $methodname){
				if(preg_match("/^get/", $methodname)){
					if($methodname!="getField" && $methodname!="getOid" && $methodname!="getData" && 
					$methodname!="getPrimaryKey" && $methodname!="getDbType" && $methodname!="getNewInstance" 
					&& $methodname!="get_Id" && $methodname!="getEntityName") {
						$stringValue .= "(".substr($methodname,3).": ".$this->$methodname().")";
					}
				}
			}
		} catch (Exception $e) {
			$context = new BaseContext();
			$context->logException($e);
		}
		
		return $stringValue;
	}
	
	
}
?>